const mongoose = require("mongoose");
mongoose.pluralize(null); //去掉集合后面的s
const { Schema, model } = mongoose;
const versionKey = { versionKey: false };
const moment = require("moment");
moment.locale("zh-cn");
// 用户发表的游记表
const ArticleSchema = new Schema(
    {
      author_uid: String, //文章作者id
      author_id: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "user",
        required: true,
      },
      title: {
        //游记标题
        type: String,
        trim: true,
      },
      content: String, //游记内容
      cover_image: {
        //封面图片
        url: String,
        width: Number,
        height: Number,
      },
      image: {
        //图片的合集
        type: Array,
        default: [],
      },
      videoUrl: {
        //视频的url
        url: {
          type: String,
          default: "",
        },
        width: {
          type: Number,
          default: 0,
        },
        height: {
          type: Number,
          default: 0,
        },
      },
      fileType: {
        //判断文件类型:image:'图片',video:'视频'
        type: String,
        default: "image",
      },
      city: String, //游记城市
      address: String, //游记地址
      province: String, //游记省份
      tag: {
        type: Array,
        default: [],
      },
      time: {
        type: String,
        default: () => moment().utcOffset(8).format("YYYY-MM-DD"),
      },
      time_stamp: {
        type: Number,
        default: () => moment().unix(),
      },
    },
    versionKey
  );

  module.exports = {
    modelArticle:model("usertravel",ArticleSchema) 
  }